oo::class create FileContainer {
    variable Cwd File CodePad Container Lang Plugins ReadOnly

    constructor {path plugins {file {}}} {
        set ReadOnly 0
        set Plugins $plugins
        my setMetaData $file
        set extension ::[string totitle [string range [file extension $file] 1 end]]
        set Lang [expr {$file != {} && [my ifLangSupported? $extension] ? $extension : "::Fundamental"}]
        my createContainer $path
    }

    method createContainer {path} {
        set Container [frame $path]
        set CodePad [CodePad new $Container.pad $Lang $Plugins]
        set btags [bindtags $Container.pad]
        bindtags $Container.pad [linsert $btags 2 [join [lreplace [split $path .] end end] .]]
        return $Container
    }

    method ifLangSupported? {lang} {
        foreach l [info class subclasses Language] {
            if {$l == $lang} {return 1}
        }
        return 0
    }

    method setMetaData {file} {
        set File $file
        set Cwd [expr {$file == {} ? [pwd] : [file dirname $file]}]
        cd $Cwd

        set extension ::[string totitle [string range [file extension $file] 1 end]]
        set lang [expr {$file != {} && [my ifLangSupported? $extension] ? $extension : "::Fundamental"}]
        if [info exists Lang] {
            if {$lang != $Lang} {
                set Lang $lang
                my rebuildCodePad
                # $CodePad changeLang $Lang
            }
        } else {
            set Lang $lang
        }
    }

    method rebuildCodePad {} {
        set padWidget [set [info object namespace $CodePad]::PadWidget]
        set content [$padWidget get 1.0 end]
        $CodePad destroy
        set CodePad [CodePad new $Container.pad $Lang $Plugins]
        $padWidget insert 1.0 $content
    }

    destructor {
        $CodePad destroy
        destroy $Container
    }
}